
******MICROCREDIT OUTCOMES (TABLE 2; TABLE C.2 PANEL A; TABLE C.3 COLS 1 & 3)********

set more off
clear all 
clear matrix
capture log close


adopath + "$main/DoFiles"																		

local seed = 999
local reps = 5000




//--> DATA: MICROCREDIT OUTCOMES

		use "$data/credit_fa_vars.dta", clear
	
//--> DATA: FA TREATMENT STATUS 

		sort fw_code
		merge fw_code using "$data/FWHR.dta"
		drop _m

//--> DATA: BASELINE VARS

		preserve
			use "$data/baseline_fa_vars.dta", clear
			local credit_var weighted_num_active_loan weighted_num_new_loan weighted_amount_issue wmiss_pay_maturity_month inv_ratio_miss_pay_month inv_ratio_miss_pay_20 stdcredit_index
			foreach v in `credit_var' {
				rename `v' `v'0
				}
			sort fw_code
			tempfile temp
			save `temp'
		restore
		
		sort fw_code
		merge fw_code using `temp'
		drop _m
	
		//--> REGION DUMMIES
				tab region, gen(r)
	

//--> OUTPUT: TABLE 2 (CREDIT OUTCOMES: TRIGGERS AND INDEX)	 
	*********************************************************************************************************************************************************
	
	
	
		//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************		
	
			local credit_var weighted_num_active_loan inv_ratio_miss_pay_20 stdcredit_index
			local replace  replace 
			foreach v in `credit_var'{
				reg `v' `v'0 m`v' r1 r2 r3 treat_credit treat_sm
				sum `v' if treat==0
				local m = r(mean)
				outreg2 using "$output/table2 (coeff).xls", `replace' addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				local replace
				}
				
			
				
		log using "$output/table2 (p-values)", replace	
		
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
					cgmwildboot weighted_num_active_loan weighted_num_active_loan0 r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot inv_ratio_miss_pay_20 inv_ratio_miss_pay_200 minv_ratio_miss_pay_20 r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot stdcredit_index stdcredit_index0 mstdcredit_index r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					
					
							
			//--> CREDIT VS. SOCIAL
			
					g x1 = treat_credit + treat_sm
					g test1 = treat_credit //RELEVANT VAR FOR F TEST
						
					cgmwildboot weighted_num_active_loan weighted_num_active_loan0 r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot inv_ratio_miss_pay_20 inv_ratio_miss_pay_200 minv_ratio_miss_pay_20 r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot stdcredit_index stdcredit_index0 mstdcredit_index r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
				

		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
					foreach v in `credit_var' {
						randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm `v'0 m`v' r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
						}
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
					foreach v in `credit_var' {
						randcmd((treat_credit) reg `v' treat_credit x1 `v'0 m`v' r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						}
			
	log close
	*********************************************************************************************************************************************************

	
	
//--> OUTPUT: ONLINE APPENDIX TABLE C.2	(CREDIT OUTCOMES: ALL COMPONENTS OF INDEX)	 
	*********************************************************************************************************************************************************
	
	drop x1
	drop test1
	
	
	
	//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************		
	
			local credit_var weighted_num_active_loan inv_ratio_miss_pay_20 weighted_num_new_loan weighted_amount_issue inv_ratio_miss_pay_month wmiss_pay_maturity_month
			local replace  replace 
			foreach v in `credit_var'{
				reg `v' `v'0 m`v' r1 r2 r3 treat_credit treat_sm
				sum `v' if treat==0
				local m = r(mean)
				outreg2 using "$output/tableC_2A (coeff).xls", `replace' addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				local replace
				}
				
		log using "$output/tableC_2A (p-values)", replace	

				
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
					cgmwildboot weighted_num_active_loan weighted_num_active_loan0 r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot inv_ratio_miss_pay_20 inv_ratio_miss_pay_200 minv_ratio_miss_pay_20 r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot weighted_num_new_loan weighted_num_new_loan0 r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot weighted_amount_issue weighted_amount_issue0 r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot inv_ratio_miss_pay_month inv_ratio_miss_pay_month0 minv_ratio_miss_pay_month r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')	
					cgmwildboot wmiss_pay_maturity_month wmiss_pay_maturity_month0 r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
					g x1 = treat_credit + treat_sm
					g test1 = treat_credit //RELEVANT VAR FOR F TEST
						
					cgmwildboot weighted_num_active_loan weighted_num_active_loan0 r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot inv_ratio_miss_pay_20 inv_ratio_miss_pay_200 minv_ratio_miss_pay_20 r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot weighted_num_new_loan weighted_num_new_loan0 r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot weighted_amount_issue weighted_amount_issue0 r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot inv_ratio_miss_pay_month inv_ratio_miss_pay_month0 minv_ratio_miss_pay_month r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					cgmwildboot wmiss_pay_maturity_month wmiss_pay_maturity_month0 r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
				

		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
					foreach v in `credit_var' {
						randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm `v'0 m`v' r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
						}
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
					foreach v in `credit_var' {
						randcmd((treat_credit) reg `v' treat_credit x1 `v'0 m`v' r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						}
			
	log close
	*********************************************************************************************************************************************************

	

//--> OUTPUT: ONLINE APPENDIX TABLE C.3; COL 1 (CREDIT OUTCOME: INDEX w/ FULL CONTROLS)	
	*********************************************************************************************************************************************************


	drop x1
	drop test1

	
	local add_control age female marital_status head_hh education consumption_hh work_month nfirst_job work_vb weighted_num_co_alive  still_work_nrsp_2years overtime_perday credit_bonus soc_help_credit volunteer_before_nrsp job_like_help
	
	
	//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************		
		
			
				reg stdcredit_index stdcredit_index0 mstdcredit_index `add_control' r1 r2 r3 treat_credit treat_sm
				sum stdcredit_index if treat==0
				local m = r(mean)
				outreg2 using "$output/tableC_3_col1 (coeff).xls", replace addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				

			
				
		log using "$output/tableC_3_col1 (p-values)", replace	

				
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
					cgmwildboot stdcredit_index stdcredit_index0 mstdcredit_index `add_control' r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
					g x1 = treat_credit + treat_sm
					g test1 = treat_credit //RELEVANT VAR FOR F TEST
						
					cgmwildboot stdcredit_index stdcredit_index0 mstdcredit_index `add_control' r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
									

		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
						randcmd((treat_credit treat_sm) reg stdcredit_index treat_credit treat_sm stdcredit_index0 mstdcredit_index `add_control' r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
						
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
						randcmd((treat_credit) reg stdcredit_index treat_credit x1 stdcredit_index0 mstdcredit_index `add_control' r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						
			
	log close
	*********************************************************************************************************************************************************
	

	
//--> OUTPUT: ONLINE APPENDIX TABLE C.3; COL 3 (CREDIT OUTCOME: INDEX w/ VERFIED MPRS SAMPLE)
	*********************************************************************************************************************************************************
	
	drop x1
	drop test1
	
	//--> VERIFIED MPRS SAMPLE ONLY
	
			sort fw_code
			merge fw_code using "$data/social_fa_vars.dta"
			keep if _m==3
			drop _m
	
	//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************		
		
			
				reg stdcredit_index stdcredit_index0 mstdcredit_index `add_control' r1 r2 r3 treat_credit treat_sm
				sum stdcredit_index if treat==0
				local m = r(mean)
				outreg2 using "$output/tableC_3_col3 (coeff).xls", replace addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				local replace
	
			
				
		log using "$output/tableC_3_col3 (p-values)", replace	

				
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
					cgmwildboot stdcredit_index stdcredit_index0 mstdcredit_index `add_control' r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
					g x1 = treat_credit + treat_sm
					g test1 = treat_credit //RELEVANT VAR FOR F TEST
						
					cgmwildboot stdcredit_index stdcredit_index0 mstdcredit_index `add_control' r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
									

		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
						randcmd((treat_credit treat_sm) reg stdcredit_index treat_credit treat_sm stdcredit_index0 mstdcredit_index `add_control' r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
						
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
						randcmd((treat_credit) reg stdcredit_index treat_credit x1 stdcredit_index0 mstdcredit_index `add_control' r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						
			
	log close
	*********************************************************************************************************************************************************
	
		
